using System;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;

namespace Utility
{
    public class UtilityTool
    {
        private static readonly Random ram = new Random();
        internal static DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();
        internal static byte[] DSAHash;
        private static int random;

        internal static int Random
        {
            get
            {
                if (random == 0)
                {
                    random = 0xc350;
                }
                else
                {
                    random = ram.Next(0xc351);
                }
                int r = random;
                random++;
                return r;
            }
        }

        public static string RestoreXml(string encoded, int key)
        {
            char[] chArray = null;
            int num2 = 0;
            ushort num3 = 0;
            ushort num = (ushort)key;
            if ((num3 - ((uint)key)) >= 0)
            {
                goto Label_007B;
            }
        Label_001B:
            num2++;
        Label_001F:
            if ((num2 < (encoded.Length / 4)) || ((((uint)key) - num) < 0))
            {
                num3 =
                    (ushort)
                    ((((encoded[4 * num2] - 'a') + ((encoded[(4 * num2) + 1] - 0x61) << 4)) +
                      ((encoded[(4 * num2) + 2] - 0x61) << 8)) + ((encoded[(4 * num2) + 3] - 0x61) << 12));
                if ((((uint)key) - num3) >= 0)
                {
                    num3 = (ushort)(num3 - num);
                    chArray[num2] = (char)num3;
                    num = (ushort)(num + 0x6fd);
                    goto Label_001B;
                }
            }
            else
            {
                return new string(chArray);
            }
        Label_007B:
            chArray = new char[encoded.Length / 4];
            num2 = 0;
            goto Label_001F;
        }

        public static void Check()
        {
            DSA.FromXmlString(
                string.Intern(
                    "<DSAKeyValue><P>v7aWx402hheC7WRlmLBlBE/DL3CI8b/Vmj/dCEQRMao1kVRmGL/fWhJGrnQUg4OU/cISGW1+DSu/iIhSKBZV4Q==</P><Q>qRjCfkW/dk6mL4iUSTb5dZTKx30=</Q><G>aXWT+c/HfeIDCPzilyuoMXd1tHV3n1uiBa35dDRZqZ25o9PmMtaeHIBZAGPik5/qhDGf+sGm76QAGs5PzmM3dA==</G><Y>vaN0xn2qkHfnvP000Ikyln91yvkVB3QEK3zcFaFeRNwGpYEk6d05pzuLawRIWooEal69t/WpxoGNISrceWbX2w==</Y><J>AAAAASI9YDfVQAA6rOuPjZPJx4gSY6rN9myuXanRB2dUfwKYNpmqreqdbFD9NlNg</J><Seed>Z7UfhiqEbRBHn4yq4GYjuX/XMFI=</Seed><PgenCounter>Hw==</PgenCounter></DSAKeyValue>"));
            DSAHash = Encoding.ASCII.GetBytes("IrisSkin is good !!!");

            Hashtable forbidenList = new Hashtable();
            forbidenList.Add("flcRzsRtDNr2XBiCoY7NrAC352AiFA/4YuLs4nDCyOHZX5xvWtgH/g==", null);
            forbidenList.Add("isBx30VBCC0GTnJuOKmQ0jK7I8NqeyOjDigXGIG5v1dN7aw4qc3Ogw==", null);
            forbidenList.Add("ecnxRzSw41ooyZ3w+vP7BA/9xi6EbB8BsiDPhMzqSePbHiajxWGq1g==", null);
            forbidenList.Add("AMp595aFyCLiX9mmhNxVynUGqD6DCKzPQVNHBVQ2QLo7XqNs6RmGlw==", null);
            forbidenList.Add("n7cKULtvGKV9Xvrwywp6jEjZtTJqexLVUVJm+5BfuNMgk1tYsIPRmw==", null);
            forbidenList.Add("SNGT5UM73U2XvU5Xne6U9Ipns9yHdX4jNWanSFjpzqPhlphmkzqRvA==", null);
            forbidenList.Add("dP/xcFztQ8xh79YARtmtbkSrEF5X18iJBPsNH3t9OIqnsfIsarZSxQ==", null);
            forbidenList.Add("TEzGuUzla0JsvCCAh4zjutdxHRRuPe7f6nx82GAR9Eza0Iq/STDOfg==", null);
            forbidenList.Add("TT73KCbsZaEDZGPgtZig3XyF7EwI3PUPuepezqhi2Rwxpkg+ndxsXA==", null);


            if ((Random % 0xc350) == 0)
            {
                try
                {
                    byte[] sst = Convert.FromBase64String("TT73KCbsZaEDZGPgtZig3XyF7EwI3PUPuepezqhi2Rwxpkg+ndxsXA==");

                    if (forbidenList.Contains(Convert.ToBase64String(Encoding.ASCII.GetBytes("ss"))))
                    {
                        InvalidSerialNum();
                    }
                    DSA.VerifyData(DSAHash,
                                   Convert.FromBase64String("TT73KCbsZaEDZGPgtZig3XyF7EwI3PUPuepezqhi2Rwxpkg+ndxsXA=="));
                    if (!DSA.VerifyData(DSAHash, Convert.FromBase64String("TT73KCbsZaEDZGPgtZig3XyF7EwI3PUPuepezqhi2Rwxpkg+ndxsXA==")))
                    {
                        InvalidSerialNum();

                    }
                }
                catch
                {
                    InvalidSerialNum();
                }
            }
        }

        public static string GenerateKey()
        {
            return Convert.ToBase64String(DSA.SignData(Encoding.ASCII.GetBytes("123")));
        }
        private static void InvalidSerialNum()
        {
            MessageBox.Show(
                       string.Intern(
                           RestoreXml(
                               "peloagcpofjpfgaapahamfoalffbffmbkedccfkcodbdheidhpodhdgeaenemdefpdlfjccgocjgadahcdhhmnnhkbfiecmidncjfckjlbbkmbikmapklaglkanlbbempalmnpbnhajnhppndpgomknomoepfplpdpcajpjanjabjohbnnobejfcklmcaoddenkdlnbeilienmpeimgfkmnffiegghlgmjchgljhngaidmhigloijlfjbgmjkkdkekkkdkblkjilcfplijgmaknmffengelndjcomijociaplhhpkiopjhfabdmaaidbahkbpgbcogicfhpcdhgdbgndlgeeecleaacfkpif",
                               0x70eafb)) +
                       string.Intern(
                           RestoreXml(
                               "cmfdlmmdimdebmkeiibfkhifhhpfmlggjlngglehkglhmkcilkjibkajjjhjakojjjfknimkijdlpeklbibmkiimfipmeegnlhnnbieofhlomhcpjhjpogaajghalgoajcfb",
                               0x419b355a)), " ");
        }
    }
}